package com.cg.design.graphicdesignpattern.strategy;

import org.junit.Test;

/**
 * Strategy策略模式测试类
 *
 * @program: LeetCode->StrategyTest
 * @description: Strategy策略模式测试类
 * @author: cg
 * @create: 2022-03-24 19:19
 **/
public class StrategyTest {

    @Test
    public void testStrategy() {
        Player player1 = new Player("Taro", new WinningStrategy(314));
        Player player2 = new Player("Hana", new ProbStrategy(15));
        //Player player2 = new Player("Hana", new RandomStrategy(15));
        for (int i = 0; i < 100; i++) {
            Hand hand1 = player1.nextHand();
            Hand hand2 = player2.nextHand();
            if (hand1.isStrongerThan(hand2)) {
                System.out.println("Winner:" + player1);
                player1.win();
                player2.lose();
            } else if (hand2.isStrongerThan(hand1)) {
                System.out.println("Winner:" + player2);
                player1.lose();
                player2.win();
            } else {
                System.out.println("Even...");
                player1.even();
                player2.even();
            }
        }
        System.out.println("Total result:");
        System.out.println(player1.toString());
        System.out.println(player2.toString());

        String[] data = {
                "Dumpty", "Bowman", "Carroll", "Elfland", "Alice",
        };
        //SortAndPrint print = new SortAndPrint(data, new SelectionSorter());
        SortAndPrint print = new SortAndPrint(data, new QuickSorter());
        print.execute();
    }

}
